В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
A leaked Telegram discussion by 50 so-called crypto influencers has exposed the extraordinary steps they take in order to profit on the back off unsuspecting defi investors. According to a leaked screenshot of the chat, an elaborate plan to defraud defi investors using the worthless “$Few” tokens had been hatched. $Few tokens would be airdropped to some of the influencers who in turn promoted these to unsuspecting followers on Twitter.
Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.Библиотека Python разработчика | Книги по питону from in